package com.example.swd1.gudong.main.user.myrecord;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.swd1.gudong.R;

import java.util.List;

/**
 * Created by user on 9/13/16.
 */
public class UserRecordAdapter extends BaseAdapter {
    private List<UserRecordActivity.UserRecord> userRecords;
    private Context context;

    public UserRecordAdapter(Context context, List<UserRecordActivity.UserRecord> userRecords) {
        this.userRecords = userRecords;
        this.context = context;
    }

    @Override
    public int getCount() {
        return userRecords.size();
    }

    @Override
    public Object getItem(int position) {
        return userRecords.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder ;
        if (convertView == null) {
            holder= new ViewHolder();
            convertView = View.inflate(context, R.layout.item_user_record, null);
            holder.titleView= (TextView) convertView.findViewById(R.id.tv_user_record_title);
            holder.timeView= (TextView) convertView.findViewById(R.id.tv_user_record_time);
            holder.distanceView= (TextView) convertView.findViewById(R.id.tv_user_record_distance);
            holder.kmView = (TextView) convertView.findViewById(R.id.tv_user_record_km);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        UserRecordActivity.UserRecord record = userRecords.get(position);
        holder.titleView.setText(record.getTitleId());
        holder.timeView.setText(record.getDate());
        holder.distanceView.setText(record.getDistance());
        holder.kmView.setText(record.getKm());
        return convertView;
    }

    private class ViewHolder {
        TextView titleView;
        TextView timeView;
        TextView distanceView;
        TextView kmView;
    }
}
